package navigation.wzg.com.navigation.activities;

import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import navigation.wzg.com.navigation.R;
import navigation.wzg.com.navigation.Soaked.Soaked;

public class Feedback extends AppCompatActivity {

    @BindView(R.id.uu)
    LinearLayout uu;
    @BindView(R.id.update_toolbar)
    Toolbar updateToolbar;
    @BindView(R.id.feed)
    EditText feed;
    @BindView(R.id.Emailfeed)
    Button Emailfeed;
    @BindView(R.id.QQfeed)
    Button QQfeed;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        ButterKnife.bind(this);
        Soaked.initState(this, uu);
        updateToolbar.setTitle("反馈");
        setSupportActionBar(updateToolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        updateToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
                overridePendingTransition(R.anim.out, R.anim.up);
            }
        });
    }

    @OnClick({R.id.Emailfeed, R.id.QQfeed})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.Emailfeed:
                String[] email = {"2223929266@qq.com"}; // 需要注意，email必须以数组形式传入
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType("message/rfc822"); // 设置邮件格式
                intent.putExtra(Intent.EXTRA_EMAIL, email); // 接收人
                intent.putExtra(Intent.EXTRA_CC, email); // 抄送人
                intent.putExtra(Intent.EXTRA_SUBJECT, "反馈"); // 主题
                intent.putExtra(Intent.EXTRA_TEXT, feed.getText().toString()); // 正文
                startActivity(Intent.createChooser(intent, "请选择邮件类应用"));
                break;
            case R.id.QQfeed:
                new AlertDialog.Builder(this)
                        .setTitle("通知：")
                        .setMessage("将跳转到QQ?")
                        .setNegativeButton("取消", null)
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                String qqUrl = "mqqwpa://im/chat?chat_type=wpa&uin=2223929266&version=1";
                                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(qqUrl)));
                            }
                        }).show();
                break;
        }
    }
}
